package com.silence.springboot.service.impl;


import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.silence.springboot.convert.DailyHealthInfoConvert;
import com.silence.springboot.entity.DailyHealthInfoEntity;
import com.silence.springboot.mapper.DailyHealthInfoMapper;
import com.silence.springboot.service.DailyHealthInfoService;
import com.silence.springboot.vo.input.PageDailyHealthInfoInput;
import com.silence.springboot.vo.input.SaveDailyHealthInfoInput;
import com.silence.springboot.vo.output.PageDailyHealthInfoOutput;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import static com.silence.springboot.entity.table.DailyHealthInfoEntityTableDef.DAILY_HEALTH_INFO_ENTITY;

/**
 * 每日健康管理表 服务层实现。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DailyHealthInfoServiceImpl extends ServiceImpl<DailyHealthInfoMapper, DailyHealthInfoEntity> implements DailyHealthInfoService {

    /**
     * 转换器
     */
    private final DailyHealthInfoConvert dailyHealthInfoConvert;

    /**
     * 分页查询每日健康管理表
     *
     * @param input 入参
     * @return 分页结果
     */
    @Override
    public Page<PageDailyHealthInfoOutput> pageInfo(PageDailyHealthInfoInput input) {
        Page<DailyHealthInfoEntity> page = Page.of(input.getPageNum(), input.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create()
                .select(DAILY_HEALTH_INFO_ENTITY.ALL_COLUMNS)
                .from(DAILY_HEALTH_INFO_ENTITY)
                .where(DAILY_HEALTH_INFO_ENTITY.NAME.like(input.getName(), StringUtils::isNotBlank))
                .where(DAILY_HEALTH_INFO_ENTITY.STUDENT_NUMBER.eq(input.getStudentNumber(), StringUtils::isNotBlank))
                .where(DAILY_HEALTH_INFO_ENTITY.PHONE.eq(input.getPhone(), StringUtils::isNotBlank))
                .where(DAILY_HEALTH_INFO_ENTITY.CONTACT_SCREENING.eq(input.getContactScreening(), StringUtils::isNotBlank));
        return dailyHealthInfoConvert.convertPageDailyHealthInfoOutput(page(page, queryWrapper));
    }

    /**
     * 保存每日健康信息
     *
     * @param input 入参
     */
    @Override
    public void saveInfo(SaveDailyHealthInfoInput input) {
        save(dailyHealthInfoConvert.convertDailyHealthInfoEntity(input));
    }
}